<template>
  <div>
    <title-panel />
    <van-field label="销售日期" input-align="right" required is-link readonly v-model="contentObj.salesDate">
    </van-field>
    <van-field
      label="销售金额（元）"
      v-model="contentObj.salesAmount"
      label-width="40%"
      readonly
      input-align="right"
      required
    >
    </van-field>
    <van-field
      label="销售去向"
      input-align="right"
      is-link
      required
      readonly
      v-model="contentObj.subjectEnterpriseInfo.enterpriseName"
    >
    </van-field>
    <van-field
      label="生鲜乳总数量（kg）"
      v-model="contentObj.freshMilkTotal"
      label-width="40%"
      input-align="right"
      required
      readonly
    >
    </van-field>
    <template v-if="milkStationFlag == 0">
      <title-panel title="自产信息" />
      <van-field
        label="生鲜乳数量（kg）"
        v-model="contentObj.selfFreshMilkTotal"
        label-width="40%"
        input-align="right"
        required
        readonly
      >
      </van-field>
      <title-panel title="收购明细" />
      <div v-for="(item, index) in contentObj.saleInfoModels" :key="index" style="margin-bottom: 10px">
        <van-form>
          <van-field
            input-align="right"
            required
            readonly
            clickable
            label="生鲜乳来源"
            label-width="10em"
            v-model="item.sourceEnterpriseName"
            is-link
          >
          </van-field>
          <van-field
            input-align="right"
            required
            readonly
            label="销售批次"
            label-width="10em"
            v-model="item.salesBatchNo"
          />
          <van-field
            input-align="right"
            required
            readonly
            label="生鲜乳总数量"
            type="number"
            label-width="10em"
            v-model="item.freshMilkTotal"
          />
        </van-form>
      </div>
    </template>
    <template v-if="contentObj.salesStatus == 2">
      <title-panel title="作废信息" />
      <van-cell required title="作废原因" :label="contentObj.reasonForCancellation" />
    </template>
    <div style="height: 85px"></div>
    <template v-if="contentObj.salesStatus == 0">
      <div class="m-b-10 shop">
        <div class="flex-between bottom content font-14 line-height-2">
          <div class="col-8686 text-center footerImg" @click="goCompile" style="width: 50%">
            <img src="../../assets/img/bianji.png" alt="" />
            编辑
          </div>
          <div class="border"></div>
          <div class="col-8686 text-center footerImg" @click="deleteContent" style="width: 50%">
            <img src="../../assets/img/shanchu.png" alt="" />
            删除
          </div>
        </div>
      </div>
    </template>
  </div>
</template>
<script>
import { Form, Field, Dialog, Toast, DatetimePicker, Picker, Button, Cell, Popup } from 'vant'

import TitlePanel from '@/components/titlePanel'
import { getValue, setValue, clearValue } from '@/utils/auth'
import { postHandle, getHandle } from '@/api'
export default {
  components: {
    TitlePanel,
    [Form.name]: Form,
    [Field.name]: Field,
    [Picker.name]: Picker,
    [DatetimePicker.name]: DatetimePicker,
    [Button.name]: Button,
    [Popup.name]: Popup,
    [Toast.name]: Toast,
    [Cell.name]: Cell,
    [Dialog.Component.name]: Dialog.Component
  },
  data() {
    return {
      contentObj: {
        subjectEnterpriseInfo: {}
      },
      milKId: getValue('milKId'),
      milkStationFlag: getValue('milkStationFlag'),
      sellDate: '',
      // 收购明细数据数组
      shouGouDetail: [
        {
          source: '',
          productID: '',
          productNum: ''
        }
      ]
    }
  },
  created() {
    this.initialize()
  },
  methods: {
    goCompile() {
      this.$bridge.call('milkEdit')
    },
    initialize() {
      getHandle(`/agri/api/yzbzh/saleInfo/queryDetail/${this.milKId}`).then(res => {
        this.contentObj = res.data
      })
    },
    beforeClose(action, done) {
      if (action === 'confirm') {
        setTimeout(() => {
          postHandle(`/agri/api/yzbzh/saleInfo/delete/${this.milKId}`).then(res => {
            if (res.status == '0') {
              this.$toast.success(res.msg)
              done()
              clearValue('milkId')
              this.$bridge.call('base.closePage')
            } else {
              this.$toast(res.msg)
              done()
            }
          })
        }, 1000)
      } else {
        done()
      }
    },
    deleteContent() {
      Dialog.confirm({
        title: '删除确认',
        message: '确定要删除该条记录吗？',
        confirmButtonColor: 'black',
        beforeClose: this.beforeClose
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.flex-between {
  line-height: 2em;
}
::v-deep .van-cell::after {
  border-color: #eeeeee !important;
}
::v-deep .van-cell:last-child {
  border: none !important;
}
.footerImg {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #37b5b5;
  > img {
    width: 22px;
    height: 22px;
  }
}
.shop .bottom {
  position: fixed;
  bottom: 0;
  height: 68px;
  width: 100%;
  box-sizing: border-box;
  background: #ffffff;
  padding: 8px 10px 8px 14px;
  box-shadow: 0px -2px 5px 0px rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.addbtn {
  width: 50px;
  height: 24px;
  font-size: 13px;
  padding: 0;
  margin-top: 2px;
}
.border {
  height: 68px;
  width: 1px;
  background: #eeeeee;
}
</style>
